<body>
    <h1>0</h1>
</body>


<script>
    setInterval(function () {
        var fontobj = document.createElement('div')
        fontobj.className = 'font'

        var min = 0
        var max = 25
        var index = Math.floor(Math.random() * (max - min + 1) + min)
        fontobj.innerText = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')[index]


        // 左右随机
        var leftmin = 0
        var leftmax = (window.innerWidth || document.documentElement.clientWidth)
        var left = Math.floor(Math.random() * (leftmax - leftmin + 1) + leftmin)
        // 上下随机
        var topmin = 0
        var topmax = (window.innerHeight || document.documentElement.clientHeight)
        var top = Math.floor(Math.random() * (topmax - topmin + 1) + topmin)


        fontobj.style.position = 'absolute'
        fontobj.style.left = left + 'px'
        fontobj.style.top = top + 'px'
        document.body.appendChild(fontobj)
    }, 1000)

    // 键盘松开
    document.onkeyup = function (evt) {
        var e = evt || window.event
        var fonts = document.querySelectorAll('div.font')
        fonts.forEach(function (item) {
            if (item.innerText.toLowerCase() === e.key.toLowerCase()) {
                document.body.removeChild(item)
                var num = parseInt(document.querySelector('h1').innerText)
                document.querySelector('h1').innerText = num + 1
            }
        })
    }

</script>